package Override;

import java.util.Objects;

public class OverridePractice {
    public static void main(String[] args) {
        student a = new student("001","张三","100");
        System.out.println(a.toString());

        student b = new student("002","李四","100");
        System.out.println(a.equals(b));
    }
}

class student{
    public String code;
    public String name;
    public String grade;

    public student(String code, String name, String grade) {
        this.code = code;
        this.name = name;
        this.grade = grade;
    }

    @java.lang.Override
    public String toString() {
        return this.code+"  "+this.name+"  "+this.grade;
    }



//    @java.lang.Override
//    public boolean equals(Object obj) {
//        //判断当前对象的引用，是否和obj变量的引用相等
//        if (this == obj) {
//            return true;
//        }
//        //判断obj是否为学生类型
//        if (obj instanceof student){
//            student s =(student) obj;
//            return this.grade == s.grade;
//        }
//        return false;


    @java.lang.Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        student student = (student) o;
        return grade.equals(student.grade);
    }

    @java.lang.Override
    public int hashCode() {
        return Objects.hash(grade);
    }
}
